﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->

<UserControl
  xmlns="http://schemas.microsoft.com/client/2007"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
  xmlns:common="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common"
  x:Class="Microsoft.Windows.Controls.Samples.TreeViewStylingSample">
    <StackPanel>
        <StackPanel.Resources>
            <Style x:Key="RedItemStyle" TargetType="controls:TreeViewItem">
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <ContentControl Content="{Binding}" Foreground="Red" FontStyle="Italic" />
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="PurpleItemStyle" TargetType="controls:TreeViewItem">
                <Setter Property="Foreground" Value="Purple" />
                <Setter Property="FontWeight" Value="Bold" />
            </Style>

            <Style x:Key="ExpandedItemStyle"  TargetType="controls:TreeViewItem">
               <Setter Property="IsExpanded" Value="True" />
           </Style>
        </StackPanel.Resources>
        
        <!-- ItemContainerStyle -->
        <ContentControl Content="ItemContainerStyle" Style="{StaticResource Header}" />
        <TextBlock Style="{StaticResource Information}">
            The ItemContainerStyle is a Style applied to each child item of a
            TreeView or TreeViewItem.
        </TextBlock>
        <controls:TreeView ItemContainerStyle="{StaticResource RedItemStyle}" Margin="5">
            <controls:TreeViewItem Header="Controls" ItemContainerStyle="{StaticResource PurpleItemStyle}">
                <controls:TreeViewItem Header="AutoComplete" />
                <controls:TreeViewItem Header="Expander" />
                <controls:TreeViewItem Header="NumericUpDown" />
            </controls:TreeViewItem>
            <controls:TreeViewItem Header="Layout">
                <controls:TreeViewItem Header="DockPanel" />
                <controls:TreeViewItem Header="WrapPanel" />
                <controls:TreeViewItem Header="Viewbox" />
            </controls:TreeViewItem>
            <controls:TreeViewItem Header="Charting">
                <controls:TreeViewItem Header="ColumnSeries" />
                <controls:TreeViewItem Header="LineSeries" />
                <controls:TreeViewItem Header="PieSeries" />
            </controls:TreeViewItem>
        </controls:TreeView>
        
        <!-- HierarchicalDataTemplate -->
        <ContentControl Content="ItemContainerStyle with HierarchicalDataTemplate" Style="{StaticResource Header}" />
        <TextBlock Style="{StaticResource Information}">
            HierarchicalDataTemplate also exposes an ItemContainerStyle to use
            for styling its child items.
        </TextBlock>
        <controls:TreeView x:Name="TreeOfLife" Margin="5" ItemContainerStyle="{StaticResource ExpandedItemStyle}">
            <controls:TreeView.ItemTemplate>
                <controls:HierarchicalDataTemplate ItemsSource="{Binding Subclasses}" ItemContainerStyle="{StaticResource ExpandedItemStyle}">
                    <StackPanel>
                        <TextBlock Text="{Binding Rank}" FontSize="8" FontStyle="Italic" Foreground="Gray" Margin="0 0 0 -5" />
                        <TextBlock Text="{Binding Classification}" />
                    </StackPanel>
                </controls:HierarchicalDataTemplate>
            </controls:TreeView.ItemTemplate>
        </controls:TreeView>

        <src:SourceViewer xmlns:src="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="TreeViewStylingSample.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;

&lt;UserControl
  xmlns="http://schemas.microsoft.com/client/2007"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"
  xmlns:common="clr-namespace:Microsoft.Windows.Controls.Samples;assembly=Microsoft.Windows.Controls.Samples.Common"
  x:Class="Microsoft.Windows.Controls.Samples.TreeViewStylingSample"&gt;
    &lt;StackPanel&gt;
        &lt;StackPanel.Resources&gt;
            &lt;Style x:Key="RedItemStyle" TargetType="controls:TreeViewItem"&gt;
                &lt;Setter Property="HeaderTemplate"&gt;
                    &lt;Setter.Value&gt;
                        &lt;DataTemplate&gt;
                            &lt;ContentControl Content="{Binding}" Foreground="Red" FontStyle="Italic" /&gt;
                        &lt;/DataTemplate&gt;
                    &lt;/Setter.Value&gt;
                &lt;/Setter&gt;
            &lt;/Style&gt;

            &lt;Style x:Key="PurpleItemStyle" TargetType="controls:TreeViewItem"&gt;
                &lt;Setter Property="Foreground" Value="Purple" /&gt;
                &lt;Setter Property="FontWeight" Value="Bold" /&gt;
            &lt;/Style&gt;

            &lt;Style x:Key="ExpandedItemStyle"  TargetType="controls:TreeViewItem"&gt;
               &lt;Setter Property="IsExpanded" Value="True" /&gt;
           &lt;/Style&gt;
        &lt;/StackPanel.Resources&gt;
        
        &lt;!-- ItemContainerStyle --&gt;
        &lt;ContentControl Content="ItemContainerStyle" Style="{StaticResource Header}" /&gt;
        &lt;TextBlock Style="{StaticResource Information}"&gt;
            The ItemContainerStyle is a Style applied to each child item of a
            TreeView or TreeViewItem.
        &lt;/TextBlock&gt;
        &lt;controls:TreeView ItemContainerStyle="{StaticResource RedItemStyle}" Margin="5"&gt;
            &lt;controls:TreeViewItem Header="Controls" ItemContainerStyle="{StaticResource PurpleItemStyle}"&gt;
                &lt;controls:TreeViewItem Header="AutoComplete" /&gt;
                &lt;controls:TreeViewItem Header="Expander" /&gt;
                &lt;controls:TreeViewItem Header="NumericUpDown" /&gt;
            &lt;/controls:TreeViewItem&gt;
            &lt;controls:TreeViewItem Header="Layout"&gt;
                &lt;controls:TreeViewItem Header="DockPanel" /&gt;
                &lt;controls:TreeViewItem Header="WrapPanel" /&gt;
                &lt;controls:TreeViewItem Header="Viewbox" /&gt;
            &lt;/controls:TreeViewItem&gt;
            &lt;controls:TreeViewItem Header="Charting"&gt;
                &lt;controls:TreeViewItem Header="ColumnSeries" /&gt;
                &lt;controls:TreeViewItem Header="LineSeries" /&gt;
                &lt;controls:TreeViewItem Header="PieSeries" /&gt;
            &lt;/controls:TreeViewItem&gt;
        &lt;/controls:TreeView&gt;
        
        &lt;!-- HierarchicalDataTemplate --&gt;
        &lt;ContentControl Content="ItemContainerStyle with HierarchicalDataTemplate" Style="{StaticResource Header}" /&gt;
        &lt;TextBlock Style="{StaticResource Information}"&gt;
            HierarchicalDataTemplate also exposes an ItemContainerStyle to use
            for styling its child items.
        &lt;/TextBlock&gt;
        &lt;controls:TreeView x:Name="TreeOfLife" Margin="5" ItemContainerStyle="{StaticResource ExpandedItemStyle}"&gt;
            &lt;controls:TreeView.ItemTemplate&gt;
                &lt;controls:HierarchicalDataTemplate ItemsSource="{Binding Subclasses}" ItemContainerStyle="{StaticResource ExpandedItemStyle}"&gt;
                    &lt;StackPanel&gt;
                        &lt;TextBlock Text="{Binding Rank}" FontSize="8" FontStyle="Italic" Foreground="Gray" Margin="0 0 0 -5" /&gt;
                        &lt;TextBlock Text="{Binding Classification}" /&gt;
                    &lt;/StackPanel&gt;
                &lt;/controls:HierarchicalDataTemplate&gt;
            &lt;/controls:TreeView.ItemTemplate&gt;
        &lt;/controls:TreeView&gt;
    &lt;/StackPanel&gt;
&lt;/UserControl&gt;</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="TreeViewStylingSample.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;

namespace Microsoft.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample demonstrating TreeView styling.
    /// &lt;/summary&gt;
    [Sample("(5)Styling", DifficultyLevel.Basic)]
    [Category("TreeView")]
    public partial class TreeViewStylingSample : UserControl
    {
        /// &lt;summary&gt;
        /// Initializes a new instance of the TreeViewStylingSample class.
        /// &lt;/summary&gt;
        public TreeViewStylingSample()
        {
            InitializeComponent();

            // Fill the tree with data
            TreeOfLife.ItemsSource = Taxonomy.Life;
        }
    }
}</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
    </StackPanel>
</UserControl>